package com.zelin.yang.kotlin_demo.page

import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import com.zelin.yang.kotlin_demo.Base.BaseActivity
import com.zelin.yang.kotlin_demo.R
import com.zelin.yang.kotlin_demo.adapter.ViewPagerAdapter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity() {
    private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
        when (item.itemId) {
            R.id.navigation_home -> {
                message.currentItem = 0
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_dashboard -> {
                message.currentItem = 1
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_notifications -> {
                message.currentItem = 3
                return@OnNavigationItemSelectedListener true
            }
            R.id.navigation_my ->{
                message.currentItem = 2
                return@OnNavigationItemSelectedListener true
            }
        }
        false
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_main
    }

    override fun Initview() {
        //创建fragment 对象
        changeStatusBarTextColor(true)
        val fragments = arrayListOf<Fragment>().apply {
            add(HomeFragment())
            add(BuyFragment())
            add(NotfiyFragment())
            add(MyFragment())
        }
        val fragmentPagerAdapter = ViewPagerAdapter(supportFragmentManager)
        fragmentPagerAdapter.setFragments(fragments)
        message.setScanScroll(false)
        message.adapter = fragmentPagerAdapter
        message.offscreenPageLimit = fragments.size
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
    }

    override fun initDate() {

    }
}
